

#import "PUPhoneLogin.h"
#import "PUPerfectVC.h"
#import "IQKeyboardManager.h"
#import "IQKeyboardReturnKeyHandler.h"
#import "AppDelegate.h"

@interface PUPhoneLogin (){
    NSArray *permissions;
    NSTimer *messsageTimer;
    int messageIssssss;//短信倒计时  60s
}

@end

@implementation PUPhoneLogin

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    messageIssssss = 60;
    [self addView];
    
    //禁用IQKeyboardManager
    IQKeyboardManager *keyboardManager =  [IQKeyboardManager sharedManager];
    keyboardManager.enable = YES;
    keyboardManager.enableAutoToolbar = YES;
    
    [self.numTextField becomeFirstResponder];
}
-(void)addView{
//    UIImageView *rightImage=[[UIImageView alloc]init];
//    rightImage.frame=CGRectMake(0,0,_window_width,_window_width*0.410);
//    rightImage.image=[UIImage imageNamed:@"alphaImage"];
//    [self.view addSubview:rightImage];
    
    
    UIView *butV = [[UIView alloc] initWithFrame:CGRectMake(_window_width*0.042, _window_width*0.128, 40, 40)];
    butV.userInteractionEnabled=YES;
    [self.view addSubview:butV];
    UIImageView *imV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    imV.image = [UIImage imageNamed:@"backBtn"];
    [butV addSubview:imV];
    
    
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 40, 40);
    [leftButton addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [butV addSubview:leftButton];
    
    CGFloat x=_window_width*0.128+40;
    
    UILabel *numLab=[[UILabel alloc]init];
    numLab.frame = CGRectMake(x, _window_width*0.15, _window_width-2*x,_window_width*0.07);
    numLab.text=@"登录账号";
    numLab.textAlignment=NSTextAlignmentCenter;
    numLab.font=[UIFont systemFontOfSize:28];
    [self.view addSubview:numLab];
    
    UILabel *yzLab=[[UILabel alloc]init];
    yzLab.frame = CGRectMake(x, numLab.frame.size.height+numLab.frame.origin.y+8, _window_width-2*x,_window_width*0.07);
    yzLab.text=@"进行手机验证";
    yzLab.textColor=[UIColor colorWithHex:0x999999];
    yzLab.textAlignment=NSTextAlignmentCenter;
    yzLab.font=[UIFont systemFontOfSize:16];
    [self.view addSubview:yzLab];
    
    
    UIView *numView=[[UIView alloc]init];
    numView.frame = CGRectMake( _window_width*0.106,_window_width*0.410, _window_width*0.786,_window_width*0.786*0.169);
    numView.layer.masksToBounds = YES;
    numView.backgroundColor=[UIColor colorWithHex:0xF5F6FA];
    numView.layer.cornerRadius = numView.frame.size.height/2;
    numView.layer.borderWidth = 1;
    numView.layer.borderColor = [UIColor colorWithHex:0xE9EBED].CGColor;
    [self.view addSubview:numView];
    
    
    UILabel *jblLab=[[UILabel alloc]init];
    jblLab.frame = CGRectMake(16, 0, 30,numView.frame.size.height);
    jblLab.text=@"+86";
    jblLab.textColor=[UIColor blackColor];
    jblLab.textAlignment=NSTextAlignmentCenter;
    jblLab.font=[UIFont systemFontOfSize:14];
    [numView addSubview:jblLab];
    
    UIView *lineView=[[UIView alloc]init];
    lineView.backgroundColor=[UIColor colorWithHex:0xEEEEEE];
    lineView.frame = CGRectMake( 51,18, 1,numView.frame.size.height-36);
    [numView addSubview:lineView];
    
    
    UITextField *textField1 = [[UITextField alloc]init];
    textField1.frame=CGRectMake(55, 0, numView.frame.size.width*0.664, numView.frame.size.height);
    //    textField1.backgroundColor = [UIColor orangeColor];
    textField1.font = [UIFont systemFontOfSize:16.0f];
    textField1.textAlignment = NSTextAlignmentLeft;
    textField1.textColor=[UIColor colorWithHex:0x3C3C3C];
    textField1.delegate=self;
    textField1.placeholder=@"请输入手机号码";
    textField1.keyboardType = UIKeyboardTypeNumberPad;
    [numView addSubview:textField1];
    self.numTextField=textField1;
    
    UIView *codeView=[[UIView alloc]init];
    codeView.frame = CGRectMake( _window_width*0.106,_window_width*0.593, _window_width*0.786,_window_width*0.786*0.169);
    codeView.backgroundColor=[UIColor colorWithHex:0xF5F6FA];
    codeView.layer.masksToBounds = YES;
    codeView.layer.cornerRadius = numView.frame.size.height/2;
    codeView.layer.borderWidth = 1;
    codeView.layer.borderColor = [UIColor colorWithHex:0xE9EBED].CGColor;
    [self.view addSubview:codeView];
    
    //获取验证码
    UIButton *codeBtn=[[UIButton alloc]init];
    codeBtn.frame = CGRectMake(codeView.frame.size.width-codeView.frame.size.width*0.389-20, 0, codeView.frame.size.width*0.389,codeView.frame.size.height);
    [codeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    codeBtn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [codeBtn setTitleColor:[UIColor colorWithHex:0xFF2742] forState:UIControlStateNormal];
    [codeBtn addTarget:self action:@selector(codeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    codeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [codeView addSubview:codeBtn];
    self.codeBtn=codeBtn;
    
    UITextField *textField2 = [[UITextField alloc]init];
    textField2.frame=CGRectMake(20, 0, numView.frame.size.width*0.61, numView.frame.size.height);
//    textField2.backgroundColor = [UIColor orangeColor];
    textField2.font = [UIFont systemFontOfSize:16.0f];
    textField2.textAlignment = NSTextAlignmentLeft;
    textField2.textColor=[UIColor colorWithHex:0x3C3C3C];
    textField2.placeholder=@"请输入验证码";
//    textField2.delegate=self;
    textField2.keyboardType = UIKeyboardTypeNumberPad;
    [codeView addSubview:textField2];
    self.codeTextField=textField2;
    
    //手机号码登录
    UIButton *oneLoginBtn=[[UIButton alloc]init];
    oneLoginBtn.frame = CGRectMake( _window_width*0.106, _window_width*0.830, _window_width*0.786,_window_width*0.786*0.169);
    [oneLoginBtn setTitle:@"登录" forState:UIControlStateNormal];
    oneLoginBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    [oneLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [oneLoginBtn addTarget:self action:@selector(loginBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [oneLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
    
    oneLoginBtn.layer.masksToBounds = YES;
    oneLoginBtn.layer.cornerRadius = oneLoginBtn.frame.size.height/2;
    [self.view addSubview:oneLoginBtn];
    oneLoginBtn.enabled=NO;
    [oneLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFF729A]];
    self.oneLoginBtn=oneLoginBtn;
    self.oneLoginBtn.alpha=0.4;
    
    //协议
    _yyLabel = [[YYLabel alloc]init];
    _yyLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    _yyLabel.textAlignment = NSTextAlignmentCenter;
    _yyLabel.numberOfLines=0;
    [self.view addSubview:_yyLabel];
    [self protocolIsSelect:NO];
    
    [_yyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(oneLoginBtn.mas_bottom).offset(20*KWidthScale);
        make.left.equalTo(self.view.mas_left).offset(0);
        make.right.equalTo(self.view.mas_right).offset(0);
//        make.width.equalTo(@(_window_width/2));
        make.height.equalTo(@(40*KWidthScale));
//        make.bottom.equalTo(self.view.mas_bottom).offset(-40*KWidthScale);
    }];
    
//    _yyLabel.frame=CGRectMake(0, _window_height-40*KWidthScale-24*KWidthScale, _window_width, 24*KWidthScale);
    
   
}

//登录即同意《用户协议》、《隐私政策》和《天翼账号服务协议》
//并使用本机号码登录
- (void)protocolIsSelect:(BOOL)isSelect{
    NSString *str1 = @"登录即同意";
    NSString *str2 = @"《用户协议》";
    NSString *str3 = @"、";
    NSString *str4 = @"《隐私政策》";
    NSString *str5 = @"和";
    NSString *str6 = @"《用户违规管理办法》";
//    NSString *str7 = @"并使用本机号码登录";
    NSString *str = [NSString stringWithFormat:@"%@%@%@%@%@%@",str1,str2,str3,str4,str5,str6];
    //设置整段字符串的颜色
    UIColor *color = self.oneLoginGouSlect ? [UIColor blackColor] : [UIColor blackColor];
    NSDictionary *attributes = @{NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:10], NSForegroundColorAttributeName: color};
    
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str attributes:attributes];
    
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:str2] color:[UIColor colorWithHex:0xFF729A] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        
        
        NSDictionary *saveOpen_app_config = [Config getOpenAppConfig];
        NSString *h5_url=@"";
        if (saveOpen_app_config!=nil) {
            h5_url=saveOpen_app_config[@"h5_url"];
        }
        NSString* url = [NSString stringWithFormat:@"%@%@?p=4",h5_url,@"user_agreement"];
        PUWebViewVC *vc=[[PUWebViewVC alloc]init];
        vc.isXYEnter=1;
        vc.is_topbar=0;
        vc.url=url;
        vc.titleStr=@"用户协议";
        [self.navigationController pushViewController:vc animated:YES];
        
    }];
    
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:str4] color:[UIColor colorWithHex:0xFF729A] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        
        NSDictionary *saveOpen_app_config = [Config getOpenAppConfig];
        NSString *h5_url=@"";
        if (saveOpen_app_config!=nil) {
            h5_url=saveOpen_app_config[@"h5_url"];
        }
        NSString* url = [NSString stringWithFormat:@"%@%@?p=4",h5_url,@"privacy_policy"];
        PUWebViewVC *vc=[[PUWebViewVC alloc]init];
        vc.isXYEnter=1;
        vc.is_topbar=0;
        vc.url=url;
        vc.titleStr=@"隐私政策";
        [self.navigationController pushViewController:vc animated:YES];
    }];
    
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:str6] color:[UIColor colorWithHex:0xFF729A] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        
        NSDictionary *saveOpen_app_config = [Config getOpenAppConfig];
        NSString *h5_url=@"";
        if (saveOpen_app_config!=nil) {
            h5_url=saveOpen_app_config[@"h5_url"];
        }
        NSString* url = [NSString stringWithFormat:@"%@%@?p=4",h5_url,@"user_violation_plan"];
        PUWebViewVC *vc=[[PUWebViewVC alloc]init];
        vc.isXYEnter=1;
        vc.is_topbar=0;
        vc.url=url;
        vc.titleStr=@"用户违规管理办法";
        [self.navigationController pushViewController:vc animated:YES];
        
    }];
    

    //添加图片
    UIImage *image = [UIImage imageNamed:self.oneLoginGouSlect == NO ? @"mine_ZXWG" : @"mine_ZXG"];
    NSMutableAttributedString *attachment = [NSMutableAttributedString yy_attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:CGSizeMake(24, 24) alignToFont:[UIFont fontWithName:@"PingFangSC-Regular"  size:12] alignment:(YYTextVerticalAlignment)YYTextVerticalAlignmentCenter];
    //将图片放在最前面
    [text insertAttributedString:attachment atIndex:0];
    //添加图片的点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:[attachment string]] color:[UIColor clearColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        __weak typeof(self) weakSelf = self;
        weakSelf.oneLoginGouSlect = !weakSelf.oneLoginGouSlect;
        [weakSelf protocolIsSelect:self.oneLoginGouSlect];
        [weakSelf buttonChangeColor:self.oneLoginGouSlect];
    }];
    _yyLabel.attributedText = text;
    //居中显示一定要放在这里，放在viewDidLoad不起作用
    _yyLabel.textAlignment = NSTextAlignmentCenter;
    
//    CPCloseReasonVC *vc=[[CPCloseReasonVC alloc]init];
//    [self.navigationController pushViewController:vc animated:YES];

}
-(void)buttonChangeColor:(BOOL)select{
//    if (select==YES) {
//        self.zhuXiaoBtn.enabled=YES;
//        [self.zhuXiaoBtn setBackgroundColor:[UIColor colorWithHex:0xFE1C52]];
//    }else{
//        self.zhuXiaoBtn.enabled=NO;
//        [self.zhuXiaoBtn setBackgroundColor:[UIColor colorWithHex:0xD1D4D8]];
//    }
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(NumLoginChangeBtnBackground2) name:UITextFieldTextDidChangeNotification object:nil];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    if (messsageTimer) {
        [messsageTimer invalidate];
        messsageTimer = nil;
    }
   
}

-(void)NumLoginChangeBtnBackground2{
    if (self.numTextField.text.length >0 && self.codeTextField.text.length >0  )
    {
        [self.oneLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFF729A]];//红
        self.oneLoginBtn.alpha=1.0;
        self.oneLoginBtn.enabled = YES;
    }
    else
    {
        [self.oneLoginBtn setBackgroundColor:[UIColor colorWithHex:0xFF729A]];//灰
        self.oneLoginBtn.alpha=0.4;
        self.oneLoginBtn.enabled = NO;
    }
    
    
    if (self.numTextField.text.length >11){
        [self showSVProgressHUDStr:@"手机号码长度不能超过11位"];
        NSString *str2 = [self.numTextField.text substringWithRange:NSMakeRange(0, 11) ];
        self.numTextField.text=str2;
    }
//    if (self.codeTextField.text.length>4) {
//        NSString *str3=[self.codeTextField.text substringWithRange:NSMakeRange(0, 4)];
//        self.codeTextField.text=str3;
//        
//    }
//    if (self.numTextField.text.length ==11&&self.codeTextField.text.length==4){
//        [self loginBtnAction];
//    }

}

-(void)backBtnAction{
//    [self.navigationController popViewControllerAnimated:YES];
    [self dismissViewControllerAnimated:YES completion:^{

    }];
}

-(void)codeBtnAction{
    NSLog(@"codeBtnAction");
    if (self.numTextField.text.length == 0) {
        [self showSVProgressHUDStr:@"手机号码不能为空"];
        return;
    }
    [self sendCode];//可以发验证码
}
//登录按钮点击
-(void)loginBtnAction{
    [self loadData2];
    return;
    
//    CPPerfectVC *vc=[[CPPerfectVC alloc]init];
//    [self.navigationController pushViewController:vc animated:YES];
//    return;
    if (self.oneLoginGouSlect==NO) {
        [self showSVProgressHUDStr:@"请先同意用户协议！"];
        return;
    }
    
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD show ];
    [SVProgressHUD showWithStatus:@"正在加载中，请稍后..."];
    
    
    
    NSDictionary *dic=@{

                        @"phone":self.numTextField.text,
                        @"code":self.codeTextField.text,
                        @"type":@"phone_code",
                        @"from_channel":app_channel,
                        };

    NSString *url = [NSString stringWithFormat:@"%@/login",@""];
    NSDictionary *param = @{
                            
                            @"phone":self.numTextField.text,
                            @"code":self.codeTextField.text,
                            @"type":@"phone_code",
                            @"from_channel":app_channel,
                            @"data":dic
                            };
    __weak typeof(self)weakSelf = self;
    
    [[AFNetManager shareManager] postDataWithURLString:url parameters:param success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
        [SVProgressHUD dismiss];
        if ([successObject[@"code"] integerValue] == 0) {
            
            LiveUser *userInfo = [[LiveUser alloc] initWithDic:successObject[@"data"]];
            [Config saveProfile:userInfo];
            if ([[NSString stringWithFormat:@"%@",successObject[@"data"][@"is_complete"]]isEqualToString:@"1"]) {//已完善资料
                [[NSNotificationCenter defaultCenter] postNotificationName:@"loginSuccessUpdataNotification" object:self userInfo:nil];
                [self loginYunXin];
                [self loadInfoMy];
                [self loadAppInit];
                [weakSelf dismissViewControllerAnimated:YES completion:nil];
            }else{//未完善资料
                PUPerfectVC *vc=[[PUPerfectVC alloc]init];
                vc.isFirst=self.isFirst;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
        } else {
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
        NSLog(@"%@",error);
    }];
    
}


-(void)loadData2{
    if (self.oneLoginGouSlect==NO) {
        [self showSVProgressHUDStr:@"请先同意用户协议！"];
        return;
    }
    
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD show ];
    [SVProgressHUD showWithStatus:@"正在加载中，请稍后..."];
    
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *version=[NSString stringWithFormat:@"%@",[infoDictionary objectForKey:@"CFBundleShortVersionString"]];
    NSDictionary *param =@{
                            @"channel":@"apple",
                            @"mobile":self.numTextField.text,
                            @"code":self.codeTextField.text,
                            @"platform":@"1",
                            @"version":version,
                            @"market_id":@"",
                            @"device_id":@"",
                          };
    NSString *path=@"/auth/login";
    NSString *url1 = [NSString stringWithFormat:@"%@%@",baseUrl,path];
    [[AFNetManager shareManager] postDataWithURLString:url1 path:path parameters:param success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
        [SVProgressHUD dismiss];
        
        NSString *result=successObject[@"result"];
        
        NSString *new_flg=@"";
        NSString *im_sig=@"";
        NSDictionary *dic=@{};
        if ([successObject[@"result"] isKindOfClass:[NSString class]]) {
            //解密Base64编码的字符串
            NSString *decryptedString = [AES128 decryptString:result key:dataKey iv:dataIv];
            dic=[AES128 dictionaryWithJsonString:decryptedString];
            NSLog(@"json解析===%@",dic);
            new_flg=[NSString stringWithFormat:@"%@",dic[@"new_flg"]];
            im_sig=[NSString stringWithFormat:@"%@",dic[@"im_sig"]];
        }
        
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        [userDefaults setObject:im_sig forKey:@"im_sig"];
        [userDefaults synchronize];
        
        if ([successObject[@"code"] integerValue] == 200) {
            
            LiveUser *userInfo = [[LiveUser alloc] initWithDic:dic];
            [Config saveProfile:userInfo];
            if ([new_flg isEqualToString:@"1"]) {//未完善资料
                PUPerfectVC *vc=[[PUPerfectVC alloc]init];
                vc.isFirst=self.isFirst;
                [self.navigationController pushViewController:vc animated:YES];
            }else{//已完善资料
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"loginSuccessUpdataNotification" object:self userInfo:nil];
                

                [self loginYunXin];
                [self loadUserInfo];
                [self loadsystemconfig];
                
                if(self.isFirst==1){
                    [self dismissViewControllerAnimated:NO completion:nil];
                    AppDelegate *appDelegate=[[UIApplication sharedApplication] delegate];
                    [appDelegate addCPTabBarController];
                }else{
                    [self dismissViewControllerAnimated:YES completion:nil];
                }
               
                
                //                [self loadInfoMy];
                //                [self loadAppInit];
               
            }
            
        } else {
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"错误：%@",error);
        [SVProgressHUD dismiss];
    }];
}

-(void)loadUserInfo{
    
    NSDictionary *param =@{
                        
                          };
    NSString *path=@"/user/info";
    NSString *url1 = [NSString stringWithFormat:@"%@%@",baseUrl,path];
    [[AFNetManager shareManager] postDataWithURLString:url1 path:path parameters:param success:^(NSURLResponse *operation, id successObject) {
        
        NSString *result=successObject[@"result"];
        NSDictionary *dic=@{};
        if ([successObject[@"result"] isKindOfClass:[NSString class]]) {
            //解密Base64编码的字符串
            NSString *decryptedString = [AES128 decryptString:result key:dataKey iv:dataIv];
            dic=[AES128 dictionaryWithJsonString:decryptedString];
            NSLog(@"json解析===%@",dic);
        }
        
        if ([successObject[@"code"] integerValue] == 200||[successObject[@"code"] integerValue] == 0) {
            LiveUser *userInfo = [[LiveUser alloc] initWithDic:dic];
            userInfo.token=[Config getToken];
            [Config saveProfile:userInfo];
        } else {
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"错误：%@",error);
    }];
    
}
//登录云信
-(void)loginYunXin{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"loginYunXinNSNotification" object:self userInfo:nil];
    // 静态token鉴权
//    [[[NIMSDK sharedSDK] loginManager] login:[NSString stringWithFormat:@"%@",[Config getUser_id]] token:[NSString stringWithFormat:@"%@",[Config getToken]] authType:NIMSDKAuthTypeDefault loginExt:@"" completion:^(NSError *error)
//      {
//          if (error == nil) {
//              NSLog(@"1");
//              // 登录成功
//              // your code
//          } else {
//              NSLog(@"0");
//              // 登录失败
//              // your code
//          }
//      }];
}
-(void)loadAppInit{
    NSString *url = [NSString stringWithFormat:@"%@/app_init",@""];
    [[AFNetManager shareManager] getDataWithURLString:url parameters:nil success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
//        NSString *dataStr= successObject[@"data"];
        if ([successObject[@"code"] integerValue] == 0) {
           
            
            NSDictionary *info_api = successObject[@"data"][@"intimacy_friend"];
            NSLog(@"%@",info_api);
            [Config saveIntimacy_friendInfo:info_api];
            
            NSDictionary *info_api1 = [Config getIntimacy_friend];
            NSLog(@"%@",info_api1);
           
        }else{
//            [self showSVProgressHUDStr:successObject[@"message"]];
        }
      
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
//发送验证码
-(void)sendCode{
    [self loadData];
}


-(void)loadData{
    
    NSDictionary *param =@{
                            @"mobile":self.numTextField.text,
                            @"type":@"1",
                            @"len":@4,
                          };
    NSString *path=@"/auth/send_sms";
    NSString *url1 = [NSString stringWithFormat:@"%@%@",baseUrl,path];
    [[AFNetManager shareManager] postDataWithURLString:url1 path:path parameters:param success:^(NSURLResponse *operation, id successObject) {
        
        NSString *result=successObject[@"result"];
        NSDictionary *dic=@{};
        if ([successObject[@"result"] isKindOfClass:[NSString class]]) {
            //解密Base64编码的字符串
            NSString *decryptedString = [AES128 decryptString:result key:dataKey iv:dataIv];
            dic=[AES128 dictionaryWithJsonString:decryptedString];
            NSLog(@"json解析===%@",dic);
            NSString *code=dic[@"code"];
            NSLog(@"验证码-----%@",code);
        }
        
        //5321
        if ([successObject[@"code"] integerValue] == 200||[successObject[@"code"] integerValue] == 0) {
            self.codeTextField.text = [NSString stringWithFormat:@"%@",dic[@"code"]];
            [self NumLoginChangeBtnBackground2];
            self.codeBtn.userInteractionEnabled = YES;
            if (self->messsageTimer == nil) {
                self->messsageTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(daojishi) userInfo:nil repeats:YES];
            }
            [self.codeTextField becomeFirstResponder];
        } else {
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"错误：%@",error);
    }];
}


-(void)daojishi{
    
    [self.codeBtn setTitleColor:[UIColor colorWithHex:0xB2B2B2] forState:UIControlStateNormal];
    messageIssssss-=1;
    [self.codeBtn setTitle:[NSString stringWithFormat:@"%ds后重新获取",messageIssssss] forState:UIControlStateNormal];
    self.codeBtn.userInteractionEnabled = NO;
    if (messageIssssss<=0) {
        [self.codeBtn setTitle:@"重新获取" forState:UIControlStateNormal];
        [self.codeBtn setTitleColor:[UIColor colorWithHex:0xFF2742] forState:UIControlStateNormal];
        self.codeBtn.userInteractionEnabled = YES;
        [messsageTimer invalidate];
        messsageTimer = nil;
        messageIssssss = 60;
    }
}
-(void)showSVProgressHUDStr:(NSString *)str{
    if ([str isKindOfClass:[NSNull class]]||str==nil||[str isEqualToString:@""]) {
        return;
    }
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:str];
}
-(void)loadInfoMy{
    NSString *url = [NSString stringWithFormat:@"%@/info/my",@""];
    [[AFNetManager shareManager] getDataWithURLString:url parameters:nil success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
//        NSString *dataStr= successObject[@"data"];
        if ([successObject[@"code"] integerValue] == 0) {
            
            LiveUser *userInfo = [[LiveUser alloc] initWithDic:successObject[@"data"]];
            [Config saveProfile2:userInfo];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"loadInfoMySuccessNotification" object:self userInfo:nil];
            [self loadDetail];

        }else{
//            [self showSVProgressHUDStr:successObject[@"message"]];
        }
      
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
-(void)loadDetail{
    
    if ([[Config getSex] intValue]==1) {
        return;
    }
    if ([[Config getis_real] intValue]==1) {
        return;
    }
    
    NSString *user_id=[Config getUser_id];
    NSDictionary *param=@{
                          @"user_id":user_id,
                         };
    NSString *url = [NSString stringWithFormat:@"%@/info/detail",@""];
    [[AFNetManager shareManager] getDataWithURLString:url parameters:param success:^(NSURLResponse *operation, id successObject) {
        NSLog(@"%@",successObject);
        if ([successObject[@"code"] integerValue] == 0) {
            LiveUser *user =[Config myProfile];
            user.audit_icon = successObject[@"data"][@"audit_icon"];
            user.is_save_audit_icon = successObject[@"data"][@"is_save_audit_icon"];
            [Config updateProfile:user];
           
        }else{
            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

-(void)loadsystemconfig{

    NSDictionary *param =@{
                          };
    NSString *path=@"/system/config";
    NSString *url1 = [NSString stringWithFormat:@"%@%@",baseUrl,path];
    [[AFNetManager shareManager] postDataWithURLString:url1 path:path parameters:param success:^(NSURLResponse *operation, id successObject) {
        
        NSString *result=successObject[@"result"];
        NSDictionary *dic=@{};
        if ([successObject[@"result"] isKindOfClass:[NSString class]]) {
            //解密Base64编码的字符串
            NSString *decryptedString = [AES128 decryptString:result key:dataKey iv:dataIv];
            dic=[AES128 dictionaryWithJsonString:decryptedString];
            NSLog(@"json解析===%@",dic);
        }
        
        if ([successObject[@"code"] integerValue] == 200||[successObject[@"code"] integerValue] == 0) {
           
            
            NSDictionary *saveSystemConfig=dic;
            [Config saveSystemConfig:saveSystemConfig];
            NSDictionary *saveSystemConfig1 = [Config getSystemConfig];
            
            
        } else {
//            [self showSVProgressHUDStr:successObject[@"message"]];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"错误：%@",error);
    }];
}
@end
